home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / xvi.lha / Xvi_V1.0_Src / xvi.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-04  |  30.4 KB  |  1,091 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. /***
  3.  
  4. * @(#)xvi.h    2.5 (Chris & John Downey) 9/1/92
  5.  
  6. * program name:
  7.     xvi
  8. * function:
  9.     PD version of UNIX "vi" editor, with extensions.
  10. * module name:
  11.     xvi.h
  12. * module function:
  13.     General definitions for xvi.
  14.  
  15.     This file should really be split up into several files
  16.     rather than being concentrated into one huge monolith.
  17.  
  18. * history:
  19.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  20.     Originally by Tim Thompson (twitch!tjt)
  21.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  22.     Heavily modified by Chris & John Downey
  23.     Minor, Amiga specific modifications made by Dan Schmelzer.
  24.  
  25. ***/
  26.  
  27. /***************************************************************
  28.  *                                                             *
  29.  * SECTION 1: ENVIRONMENT                                      *
  30.  *                                                             *
  31.  * Most of this section is concerned with including the right  *
  32.  * header files; we also define some things by hand if the     *
  33.  * appropriate definitions are not provided by the system.     *
  34.  *                                                             *
  35.  ***************************************************************/
  36.  
  37. /*
  38.  * System include files ...
  39.  */
  40. #include <stdio.h>
  41. #include <signal.h>
  42. #include <string.h>
  43.  
  44. #ifdef    __STDC__
  45.  
  46. #   define  USE_STDHDRS
  47. #   define  STRERROR_AVAIL
  48. #   include <errno.h>
  49. #   include <stdarg.h>
  50. #   define  VA_START(a, b)    va_start(a, b)
  51. #   define  P(args)        args
  52.  
  53. #else    /* not __STDC__ */
  54.  
  55. #   ifdef   ultrix
  56. #       ifdef    mips
  57. #           define  USE_STDHDRS
  58. #       endif   /* mips */
  59. #   endif   /* ultrix */
  60. #   ifdef   sparc
  61. #       define    USE_STDHDRS
  62. #   endif   /* sparc */
  63. #   include <varargs.h>
  64. #   define  VA_START(a, b)    va_start(a)
  65.  
  66. #   define  P(args)         ()
  67.  
  68. #   define  const
  69. #   define  volatile
  70.  
  71. #endif    /* not __STDC__ */
  72.  
  73. #ifdef    USE_STDHDRS
  74. #   include <stdlib.h>
  75. #   include <stddef.h>
  76. #   include <limits.h>
  77. #else    /* USE_STDHDRS not defined */
  78.     extern  FILE    *fopen();
  79.     extern  char    *malloc();
  80.     extern  char    *realloc();
  81.     extern  char    *getenv();
  82.     extern  long    atol();
  83.     extern  char    *memcpy();
  84.     extern  char    *memset();
  85.     extern  void    exit();
  86. #endif    /* USE_STDHDRS not defined */
  87.  
  88. #undef USE_STDHDRS
  89.  
  90. /*
  91.  * Functions which ANSI does not specify should
  92.  * be included in any standard header file.
  93.  */
  94. extern    int    chdir P((const char *path));
  95.  
  96. #ifdef AMIGA
  97. extern    char    *getcwd P((char *, int));
  98. #else
  99. extern    char    *getcwd P((char *, unsigned));
  100. #endif
  101.  
  102. extern    void    sleep P((unsigned seconds));
  103.  
  104. /*
  105.  * If we have ANSI C, these should be defined in limits.h:
  106.  */
  107. #ifndef INT_MAX
  108. #   define INT_MAX    ((int) ((unsigned int) ~0 >> 1))
  109. #endif
  110. #ifndef INT_MIN
  111. #   define INT_MIN    (~INT_MAX)
  112. #endif
  113. #ifndef ULONG_MAX
  114. #   define ULONG_MAX    0xffffffff
  115. #endif
  116.  
  117. /*
  118.  * Macro to convert a long to an int.
  119.  * If a long is the same as an int, this is trivial.
  120.  */
  121. #define    LONG2INT(n)    (sizeof(int) == sizeof(long) ? (int) (n) : \
  122.              (int) ((n) > INT_MAX ? INT_MAX : \
  123.               ((n) < INT_MIN ? INT_MIN : (n))))
  124.  
  125.  
  126. /***************************************************************
  127.  *                                                             *
  128.  * SECTION 2: FUNDAMENTAL TYPES                                *
  129.  *                                                             *
  130.  * These types are used by other included header files.        *
  131.  *                                                             *
  132.  ***************************************************************/
  133.  
  134. /*
  135.  * Boolean type.
  136.  * It would be possible to make this an enumerated type,
  137.  * but it isn't worth the hassle - enums don't confer any
  138.  * real advantages, and it means we can't do things like
  139.  *
  140.  *    bool_t    value = (i == 47);
  141.  *
  142.  * but instead are forced to write the abominable
  143.  *
  144.  *    bool_t    value = (i == 47) ? TRUE : FALSE;
  145.  *
  146.  * which is silly.
  147.  */
  148. #undef    FALSE            /* just in case */
  149. #undef    TRUE
  150. #define    FALSE        0
  151. #define    TRUE        1
  152. typedef    int        bool_t;
  153.  
  154.  
  155. /***************************************************************
  156.  *                                                             *
  157.  * SECTION 3: FUNDAMENTAL HEADER FILES                         *
  158.  *                                                             *
  159.  * These header files define types which are used by Xvi.      *
  160.  *                                                             *
  161.  ***************************************************************/
  162.  
  163. #include "virtscr.h"
  164.  
  165.  
  166. /***************************************************************
  167.  *                                                             *
  168.  * SECTION 4: MISCELLANEOUS DEFINITIONS                        *
  169.  *                                                             *
  170.  * Definitions of limits and suchlike used within the editor.  *
  171.  *                                                             *
  172.  ***************************************************************/
  173.  
  174. /*
  175.  * Minimum number of rows a window can have, including status line.
  176.  */
  177. #define    MINROWS        2
  178.  
  179. /*
  180.  * SLOP is the amount of extra space we get for text on a line during
  181.  * editing operations that need more space. This keeps us from calling
  182.  * malloc every time we get a character during insert mode. No extra
  183.  * space is allocated when the file is initially read.
  184.  */
  185. #define    SLOP        10
  186.  
  187. /*
  188.  * The number of characters taken up by the line number
  189.  * when "number" is set; up to 6 digits plus two spaces.
  190.  */
  191. #define    NUM_SIZE    8
  192. #define    NUM_FMT        "%6ld  "
  193.  
  194. /*
  195.  * (MAX_LINE_LENGTH - 1) gives the maximum line length this editor can read in.
  196.  * Used by fileio.c (getfile()) and pipe.c (p_read()).
  197.  */
  198. #define    MAX_LINE_LENGTH    1024
  199.  
  200. /*
  201.  * Maximum value for the tabstop parameter.
  202.  */
  203. #define    MAX_TABSTOP    32
  204.  
  205. /*
  206.  * Default timeout for keystrokes (in milliseconds).
  207.  * The timeout parameter is set to this value.
  208.  */
  209. #define    DEF_TIMEOUT    200
  210.  
  211.  
  212. /***************************************************************
  213.  *                                                             *
  214.  * SECTION 5: PARAMETER TYPE DEFINITIONS                       *
  215.  *                                                             *
  216.  * These are definitions of types for particular parameters.   *
  217.  *                                                             *
  218.  ***************************************************************/
  219.  
  220. /*
  221.  * Regular expression search modes - used in search.c.
  222.  * These are the integer values to which the P_regextype
  223.  * enumerated parameter may be set. Note that these values
  224.  * are ordered; e.g. rt_GREP is considered to be earlier
  225.  * than, and/or less than, rt_EGREP. If the types are added
  226.  * to, this ordering must be maintained. Also note that the
  227.  * names in the rt_strings table must follow the same order.
  228.  */
  229. #define rt_TAGS        0    /* only ^ and $ are significant */
  230. #define rt_GREP        1    /* like grep, but with \< and \> */
  231. #define rt_EGREP    2    /* like egrep, but with \< and \> */
  232.  
  233. /*
  234.  * Array of names for the P_regextype enumeration, defined in
  235.  * search.c.
  236.  */
  237. extern    char        *rt_strings[];
  238.  
  239. /*
  240.  * Integer values for the P_preserve enumerated parameter. Note that
  241.  * the names in psv_strings must follow the same order.
  242.  */
  243. #define psv_UNSAFE    0    /* never preserve buffer before writing */
  244. #define psv_STANDARD    1    /*
  245.                  * only preserve buffer before writing
  246.                  * if it hasn't been preserved recently
  247.                  */
  248. #define psv_SAFE    2    /* always preserve buffer before writing */
  249. #define psv_PARANOID    3    /*
  250.                  * like psv_SAFE, but never remove the
  251.                  * preserve file
  252.                  */
  253.  
  254. /*
  255.  * Array of names for the P_preserve enumeration, defined in
  256.  * search.c.
  257.  */
  258. extern    char        *psv_strings[];
  259.  
  260. /*
  261.  * Integer values for the P_format enumerated parameter. These are for
  262.  * the formats we know about so far. Note that the entries in
  263.  * fmt_strings & tftable (defined in fileio.c) must follow the same order.
  264.  */
  265. #define    fmt_CSTRING    0
  266. #define    fmt_MACINTOSH    1
  267. #define    fmt_MSDOS    2
  268. #define    fmt_OS2        3
  269. #define    fmt_QNX        4
  270. #define    fmt_TOS        5
  271. #define    fmt_UNIX    6
  272.  
  273. /*
  274.  * Array of names for the P_format enumeration.
  275.  */
  276. extern    char        *fmt_strings[];
  277.  
  278. /*
  279.  * Integer values for the P_jumpscroll enumerated parameter. Note that
  280.  * the entries in js_strings (defined in param.c) must follow the same
  281.  * order.
  282.  */
  283. #define    js_OFF        0
  284. #define    js_AUTO        1
  285. #define    js_ON        2
  286.  
  287. /***************************************************************
  288.  *                                                             *
  289.  * SECTION 6: EDITOR TYPE DEFINITIONS                          *
  290.  *                                                             *
  291.  ***************************************************************/
  292.  
  293. /*
  294.  * Possible editor states.
  295.  */
  296. typedef enum {
  297.     NORMAL,            /* command mode */
  298.     INSERT,            /* insert mode */
  299.     REPLACE,            /* overwrite mode */
  300.     CMDLINE,            /* on the : command line */
  301.     DISPLAY            /* in display mode (e.g. g//p or :set all) */
  302. } state_t;
  303.  
  304. extern    state_t        State;    /* defined in main.c */
  305.  
  306. /*
  307.  * Possible return values for cmd_input(), which deals with command
  308.  * line input. This is for commands starting with :, /, ? and !.
  309.  */
  310. typedef enum {
  311.     cmd_COMPLETE,        /* user hit return (cmd line available) */
  312.     cmd_INCOMPLETE,        /* not finished typing command line yet */
  313.     cmd_CANCEL            /* user aborted command line */
  314. } Cmd_State;
  315.  
  316. /*
  317.  * Possible directions for searching, and opening lines.
  318.  */
  319. #define    FORWARD        0
  320. #define    BACKWARD    1
  321.  
  322. /*
  323.  * Line structure and its friends.
  324.  *
  325.  * The structure used to hold a line; this is used to form
  326.  * a doubly-linked list of the lines comprising a file.
  327.  *
  328.  * The definition for MAX_LINENO depends on the type of
  329.  * l_number, and on the size of the machine; we are fairly
  330.  * safe setting all bits here so long as l_number is always
  331.  * an unsigned type. Should really use a lineno_t here, and
  332.  * get rid of the need for a maximum lineno.
  333.  */
  334. typedef    struct    line {
  335.     struct line        *l_prev;    /* previous line */
  336.     struct line        *l_next;    /* next line */
  337.     char        *l_text;    /* text for this line */
  338.     int            l_size;        /* actual size of space at 's' */
  339.     unsigned long    l_number;    /* line "number" */
  340. } Line;
  341.  
  342. #define    MAX_LINENO    ULONG_MAX
  343.  
  344. /*
  345.  * These pseudo-functions operate on lines in a buffer, returning TRUE
  346.  * or FALSE according to whether l1 is later or earlier than l2.
  347.  * Note that there is no macro for "same", which is excluded by both
  348.  * "earlier" and "later".
  349.  */
  350. #define    later(l1, l2)    ((l1)->l_number > (l2)->l_number)
  351. #define    earlier(l1, l2)    ((l1)->l_number < (l2)->l_number)
  352.  
  353. /*
  354.  * This macro gives the line number of line 'l' in buffer 'b'.
  355.  */
  356. #define    lineno(b, l)    ((l)->l_number)
  357.  
  358. /*
  359.  * Easy ways of finding out whether a given line is the first
  360.  * or last line of a buffer, without needing a buffer pointer.
  361.  */
  362. #define    is_lastline(lp)    ((lp)->l_number == MAX_LINENO)
  363. #define    is_line0(lp)    ((lp)->l_number == 0)
  364.  
  365.  
  366. /*
  367.  * Structure used to hold a position in a file;
  368.  * this is just a pointer to the line, and an index.
  369.  */
  370. typedef    struct    position {
  371.     Line        *p_line;    /* line we're referencing */
  372.     int            p_index;    /* position within that line */
  373. } Posn;
  374.  
  375. /*
  376.  * This is stuff to do with marks - it should be privately defined
  377.  * in mark.c, but it needs to be related to each individual buffer.
  378.  */
  379. #define    NMARKS    10        /* max. # of marks that can be saved */
  380.  
  381. typedef    struct    mark {
  382.     char        m_name;
  383.     Posn        m_pos;
  384. } Mark;
  385.  
  386. /*
  387.  * Structure used to record a single change to a buffer.
  388.  * A change may either be a number of lines replaced with a
  389.  * new set, a number of characters removed or a number of
  390.  * characters replaced with a new set. Character changes
  391.  * never straddle line boundaries. A list of these
  392.  * structures forms a complex change. There is also a fourth
  393.  * type of "change", which does not actually change the
  394.  * buffer, but is simply a record of the cursor position at
  395.  * the time of the start of the change. This is needed so
  396.  * that the cursor returns to the correct position after an
  397.  * "undo".
  398.  *
  399.  * This entire structure is only used in undo.c and alloc.c, and
  400.  * no other code should touch it.
  401.  */
  402. typedef    struct change {
  403.     struct change    *c_next;
  404.     enum {
  405.     C_LINE,
  406.     C_CHAR,
  407.     C_DEL_CHAR,
  408.     C_POSITION
  409.     }            c_type;
  410.     unsigned long    c_lineno;
  411.     union {
  412.     struct {
  413.         long    cul_nlines;
  414.         Line    *cul_lines;
  415.     }    cu_l;
  416.     struct {
  417.         int        cuc_index;
  418.         int        cuc_nchars;
  419.         char    *cuc_chars;
  420.     }    cu_c;
  421.     struct {
  422.         long    cup_line;
  423.         int        cup_index;
  424.     }    cu_p;
  425.     }            c_u;
  426. } Change;
  427.  
  428. #define    c_nlines    c_u.cu_l.cul_nlines
  429. #define    c_lines        c_u.cu_l.cul_lines
  430. #define    c_index        c_u.cu_c.cuc_index
  431. #define    c_nchars    c_u.cu_c.cuc_nchars
  432. #define    c_chars        c_u.cu_c.cuc_chars
  433. #define    c_pline        c_u.cu_p.cup_line
  434. #define    c_pindex    c_u.cu_p.cup_index
  435.  
  436. /*
  437.  * Variable-length FIFO queue of characters.
  438.  */
  439. typedef struct
  440. {
  441.     char        *fxb_chars;    /* pointer to allocated space */
  442.     unsigned    fxb_max;    /* size of allocated space */
  443.     unsigned    fxb_rcnt;    /* number of characters read */
  444.     unsigned    fxb_wcnt;    /* number of characters written */
  445. /* public: */
  446. /*
  447.  * Initialize a Flexbuf.
  448.  */
  449. #define            flexnew(f)    ((f)->fxb_wcnt = (f)->fxb_max = 0)
  450. /*
  451.  * Reset a Flexbuf by clearing its contents, but without freeing the
  452.  * dynamically allocated space.
  453.  */
  454. #define            flexclear(f)    ((f)->fxb_wcnt = 0)
  455. /*
  456.  * Test whether a Flexbuf is empty.
  457.  */
  458. #define            flexempty(f)    ((f)->fxb_rcnt >= (f)->fxb_wcnt)
  459. /*
  460.  * Remove last character from a Flexbuf.
  461.  */
  462. #define            flexrmchar(f)    (!flexempty(f) && --(f)->fxb_wcnt)
  463. /*
  464.  * Return number of characters in a Flexbuf.
  465.  */
  466. #define            flexlen(f)    (flexempty(f) ? 0 : \
  467.                      (f)->fxb_wcnt - (f)->fxb_rcnt)
  468. }
  469. Flexbuf;
  470.  
  471. /*
  472.  * Structure used to hold all information about a "buffer" -
  473.  * i.e. the representation of a file in memory.
  474.  */
  475. typedef struct buffer {
  476.     Line        *b_line0;    /* ptr to zeroth line of file */
  477.     Line        *b_file;    /* ptr to first line of file */
  478.     Line        *b_lastline;    /* ptr to (n+1)th line of file */
  479.  
  480.     /*
  481.      * All of these are allocated, and should be freed
  482.      * before assigning any new value to them.
  483.      */
  484.     char        *b_filename;    /* file name, if any */
  485.     char        *b_tempfname;    /* name for temporary copy of file */
  486.  
  487.     unsigned int     b_flags;    /* flags */
  488.  
  489.     int            b_nwindows;    /* no of windows open on this buffer */
  490.  
  491.     /*
  492.      * The following only used in mark.c.
  493.      */
  494.     Mark        b_mlist[NMARKS];    /* current marks */
  495.     Mark        b_pcmark;        /* previous context mark */
  496.     bool_t        b_pcvalid;        /* true if pcmark is valid */
  497.  
  498.     /*
  499.      * The following only used in undo.c.
  500.      */
  501.     unsigned int    b_nlevels;    /* number of brackets surrounding */
  502.                     /* current change to buffer */
  503.     Change        *b_change;    /* ptr to list of changes made */
  504.  
  505. } Buffer;
  506.  
  507. /*
  508.  * Definitions for the "flags" field of a buffer.
  509.  */
  510. #define    FL_MODIFIED    0x1
  511. #define    FL_READONLY    0x2
  512. #define    FL_NOEDIT    0x4
  513. #define    is_modified(b)    ((b)->b_flags & FL_MODIFIED)
  514. #define    is_readonly(b)    (Pb(P_readonly) || ((b)->b_flags & FL_READONLY))
  515. #define    not_editable(b)    ((b)->b_flags & FL_NOEDIT)
  516.  
  517. /*
  518.  * Structure used to hold information about a "window" -
  519.  * this is intimately associated with the Buffer structure.
  520.  */
  521. typedef struct window {
  522.     Posn        *w_cursor;    /* cursor's position in buffer */
  523.  
  524.     Buffer        *w_buffer;    /* buffer we are a window into */
  525.  
  526.     Line        *w_topline;    /* line at top of screen */
  527.     Line        *w_botline;    /* line below bottom of screen */
  528.  
  529.     VirtScr        *w_vs;        /* virtual screen for window */
  530.  
  531.     unsigned        w_nrows;    /* number of rows in window */
  532.     unsigned        w_ncols;    /* number of columns in window */
  533.     unsigned        w_winpos;    /* row of top line of window */
  534.     unsigned        w_cmdline;    /* row of window command line */
  535.  
  536.     /*
  537.      * These are used by the ^O command to store the previous
  538.      * size of the window so that we can return to it.
  539.      */
  540.     int            w_2winpos;    /* last row of top line of window */
  541.     int            w_2nrows;    /* last no of rows in buffer window */
  542.     int            w_2cmdline;    /* last row of window command line */
  543.  
  544.  
  545.     /*
  546.      * Allocated within screen.c.
  547.      */
  548.     Flexbuf        w_statusline;    /* status information on status line */
  549.  
  550.  
  551.     /*
  552.      * These elements are related to the cursor's position in the window.
  553.      */
  554.     int            w_row, w_col;    /* cursor's position in window */
  555.  
  556.     int            w_virtcol;    /* column number of the file's actual */
  557.                     /* line, as opposed to the column */
  558.                     /* number we're at on the screen. */
  559.                     /* This makes a difference on lines */
  560.                     /* which span more than one screen */
  561.                     /* line. */
  562.  
  563.     int            w_curswant;    /* The column we'd like to be at. */
  564.                     /* This is used to try to stay in */
  565.                     /* the same column through up/down */
  566.                     /* cursor motions. */
  567.  
  568.     bool_t        w_set_want_col;    /* If set, then update w_curswant */
  569.                     /* the next time through cursupdate() */
  570.                     /* to the current virtual column */
  571.  
  572.     int            w_c_line_size;    /* current size of cursor line */
  573.  
  574.     bool_t        w_curs_new;    /* true if cursor should be updated */
  575.  
  576.     /*
  577.      * The following only used in windows.c.
  578.      */
  579.     struct window    *w_last;    /* first and last pointers */
  580.     struct window    *w_next;
  581. } Xviwin;
  582.  
  583. /*
  584.  * Values returned by inc() & dec().
  585.  */
  586. enum mvtype {
  587.     mv_NOMOVE = -1,    /* at beginning or end of buffer */
  588.     mv_SAMELINE = 0,    /* still within same line */
  589.     mv_CHLINE = 1,    /* changed to different line */
  590.     mv_EOL = 2        /* in same line, at terminating '\0' */
  591. };
  592.  
  593. /*
  594.  * Number of input characters since the last buffer preservation.
  595.  */
  596. extern volatile int    keystrokes;
  597.  
  598. /*
  599.  * Minimum number of keystrokes after which we do an automatic
  600.  * preservation of all modified buffers.
  601.  */
  602. #define PSVKEYS        60
  603.  
  604. /*
  605.  * Exceptional return values for get_file().
  606.  */
  607. #define gf_NEWFILE    ((long)-1)    /* no such file */
  608. #define gf_CANTOPEN    ((long)-2)    /* error opening file */
  609. #define gf_IOERR    ((long)-3)    /* error reading from file */
  610. #define gf_NOMEM    ((long)-4)    /* not enough memory */
  611.  
  612. /*
  613.  * Editor input events. Handled by xvi_handle_event().
  614.  */
  615. typedef struct event {
  616.     enum {
  617.     Ev_char,
  618.     Ev_timeout
  619.     }            ev_type;
  620.     union {
  621.     /* Ev_char: */
  622.     int    evu_inchar;
  623.  
  624.     /* Ev_timeout: */
  625.     }            ev_u;
  626. } xvEvent;
  627.  
  628. #define    ev_inchar    ev_u.evu_inchar
  629.  
  630.  
  631. /***************************************************************
  632.  *                                                             *
  633.  * SECTION 7: MISCELLANEOUS MACROS                             *
  634.  *                                                             *
  635.  ***************************************************************/
  636.  
  637.  
  638. /***************************************************************
  639.  *                                                             *
  640.  * SECTION 8: XVI-LOCAL HEADER FILES                           *
  641.  *                                                             *
  642.  * Various subsidiary header files with definitions relating   *
  643.  * to particular areas of the editor (or its environment).     *
  644.  * Note that these header files may use definitions in this    *
  645.  * file, so are included after all types are defined.          *
  646.  *                                                             *
  647.  ***************************************************************/
  648.  
  649. #include "ascii.h"
  650. #include "param.h"
  651. #include "ptrfunc.h"
  652.  
  653.  
  654. /***************************************************************
  655.  *                                                             *
  656.  * SECTION 9: SYSTEM-SPECIFIC HEADER FILES                     *
  657.  *                                                             *
  658.  ***************************************************************/
  659.  
  660. /*
  661.  * Include file for system interface module.
  662.  * We must have one of these.
  663.  */
  664.  
  665. #ifdef    ATARI
  666. #   include "tos.h"
  667. #   define    GOT_OS
  668. #endif
  669.  
  670. #ifdef    UNIX
  671. #   include "unix.h"
  672. #   define    GOT_OS
  673. #endif
  674.  
  675. #ifdef    OS2
  676.     /*
  677.      * Microsoft's wonderful compiler defines MSDOS, even when
  678.      * we're compiling for OS/2, but it doesn't define OS2.
  679.      * Ingenious, eh?
  680.      */
  681. #   undef MSDOS
  682. #   include "os2vio.h"
  683. #   define    GOT_OS
  684. #endif
  685.  
  686. #ifdef    MSDOS
  687. #   include "msdos.h"
  688. #   define    GOT_OS
  689. #endif
  690.  
  691. #ifdef    QNX
  692. #   include "qnx.h"
  693. #   define    GOT_OS
  694. #endif
  695.  
  696. #ifdef AMIGA
  697. #    include "amiga.h"
  698. #    define GOT_OS
  699. #endif
  700.  
  701. #ifndef    GOT_OS
  702.     no system-specific include file found
  703. #endif
  704.  
  705.  
  706. /***************************************************************
  707.  *                                                             *
  708.  * SECTION 10: GLOBAL VARIABLE DECLARATIONS                    *
  709.  *                                                             *
  710.  ***************************************************************/
  711.  
  712. /*
  713.  * Miscellaneous global vars.
  714.  */
  715. extern    Buffer        *curbuf;    /* current buffer */
  716. extern    Xviwin        *curwin;    /* current window */
  717.  
  718. extern    int        indentchars;    /* auto-indentation on current line */
  719. extern    char    *altfilename;    /* name of current alternate file */
  720. extern    char    Version[];        /* version string for :ve command */
  721.  
  722. /*
  723.  * This flag is set when a keyboard interrupt is received.
  724.  */
  725. extern volatile unsigned char kbdintr;
  726.  
  727. /*
  728.  * This one indicates whether we should display the "Interrupted"
  729.  * message.
  730.  */
  731. extern    bool_t        imessage;
  732.  
  733. /*
  734.  * This variable (defined in main.c) is a bitmap which controls the
  735.  * verbosity of screen output. The meanings of the individual bits
  736.  * are:
  737.  *
  738.  *    e_CHARUPDATE means it's OK to update individual characters in
  739.  *    any window.
  740.  *
  741.  *    e_SCROLL means it's OK to scroll any area of the screen up or
  742.  *    down.
  743.  *
  744.  *    e_REPORT means it's OK for report() to report the number of
  745.  *    lines inserted or deleted.
  746.  *
  747.  *    e_SHOWINFO means it's OK for show_file_info() to display file
  748.  *    information for any buffer.
  749.  *
  750.  *    e_BEEP: not implemented yet.
  751.  *
  752.  *    e_REGERR means it's OK for functions in search.c to display
  753.  *    messages which may have resulted from an invalid regular
  754.  *    expression string.
  755.  *
  756.  *    e_NOMATCH means it's OK for functions in search.c to complain
  757.  *    if they fail to match a regular expression at least once.
  758.  *
  759.  * If we're reading an input sequence & e_CHARUPDATE & e_SCROLL are
  760.  * turned off, no screen updating will be done until an ESC is
  761.  * received.
  762.  */
  763. extern    unsigned    echo;
  764.  
  765. #define    e_CHARUPDATE    1
  766. #define    e_SCROLL    2
  767. #define    e_REPORT    4
  768. #define    e_SHOWINFO    010
  769. #define    e_BEEP        020
  770. #define    e_REGERR    040
  771. #define    e_NOMATCH    0100
  772.  
  773. #define e_ANY        0xffff
  774.  
  775.  
  776. /***************************************************************
  777.  *                                                             *
  778.  * SECTION 11: FUNCTION DECLARATIONS                           *
  779.  *                                                             *
  780.  ***************************************************************/
  781.  
  782. /*
  783.  * Declarations of all the routines exported from the various .c files.
  784.  */
  785.  
  786. /*
  787.  * main.c
  788.  */
  789. extern    Xviwin    *xvi_startup P((VirtScr *, int, char **, char *));
  790.  
  791. /*
  792.  * alloc.c
  793.  */
  794. extern    Change    *challoc P((void));
  795. extern    void    chfree P((Change *));
  796. extern    char    *alloc P((unsigned int));
  797. extern    char    *strsave P((const char *));
  798. extern    Line    *newline P((int));
  799. extern    bool_t    bufempty P((Buffer *));
  800. extern    bool_t    buf1line P((Buffer *));
  801. extern    bool_t    endofline P((Posn *));
  802. extern    bool_t    grow_line P((Line *, int));
  803. extern    void    throw P((Line *));
  804.  
  805. /*
  806.  * ascii.c
  807.  */
  808. extern unsigned vischar P((int, char **, int));
  809.  
  810. /*
  811.  * buffers.c
  812.  */
  813. extern    Buffer    *new_buffer P((void));
  814. extern    void    free_buffer P((Buffer *));
  815. extern    bool_t    clear_buffer P((Buffer *));
  816. extern    int    nbuffers;
  817.  
  818. /*
  819.  * edit.c
  820.  */
  821. extern    bool_t    i_proc P((int));
  822. extern    bool_t    r_proc P((int));
  823. extern    void    startinsert P((int));
  824. extern    void    startreplace P((int));
  825. extern    char    *mkstr P((int));
  826.  
  827. /*
  828.  * events.c
  829.  */
  830. extern    long    xvi_handle_event P((xvEvent *));
  831.  
  832. /*
  833.  * cmdline.c
  834.  */
  835. extern    void    do_colon P((char *, bool_t));
  836. extern    void    wait_return P((void));
  837.  
  838. /*
  839.  * cursor.c
  840.  */
  841. extern    void    cursupdate P((Xviwin *));
  842. extern    void    curs_horiz P((Xviwin *, int));
  843.  
  844. /*
  845.  * ex_cmds1.c
  846.  */
  847. extern    void    do_quit P((Xviwin *, bool_t));
  848. extern    void    do_split_window P((Xviwin *));
  849. extern    bool_t    do_buffer P((Xviwin *, char *));
  850. extern    void    do_close_window P((Xviwin *, bool_t));
  851. extern    void    do_xit P((Xviwin *));
  852. extern    bool_t    do_edit P((Xviwin *, bool_t, char *));
  853. extern    void    do_args P((Xviwin *));
  854. extern    void    do_next P((Xviwin *, int, char **, bool_t));
  855. extern    void    do_rewind P((Xviwin *, bool_t));
  856. extern    bool_t    do_write P((Xviwin *, char *, Line *, Line *, bool_t));
  857. extern    void    do_wq P((Xviwin *, char *, bool_t));
  858. extern    void    do_read P((Xviwin *, char *, Line *));
  859. extern    void    do_alt_edit P((Xviwin *));
  860. extern    void    do_compare P((void));
  861.  
  862. /*
  863.  * ex_cmds2.c
  864.  */
  865. extern    void    do_shell P((Xviwin *));
  866. extern    void    do_shcmd P((Xviwin *, char *));
  867. extern    void    do_suspend P((Xviwin *));
  868. extern    void    do_equals P((Xviwin *, Line *));
  869. extern    void    do_help P((Xviwin *));
  870. extern    bool_t    do_source P((bool_t, char *));
  871. extern    char    *do_chdir P((char *));
  872. extern    void    do_cdmy P((int, Line *, Line *, Line *));
  873.  
  874. /*
  875.  * fileio.c
  876.  */
  877. extern    bool_t    set_format P((Xviwin *, Paramval, bool_t));
  878. extern    long    get_file P((Xviwin *, char *, Line **, Line **, char *,
  879.                             char *));
  880. extern    bool_t    writeit P((Xviwin *, char *, Line *, Line *, bool_t));
  881. extern    bool_t    put_file P((Xviwin *, FILE *, Line *, Line *,
  882.                 unsigned long *, unsigned long *));
  883.  
  884. /*
  885.  * find.c
  886.  */
  887. extern    Posn    *searchc P((int, int, int, int));
  888. extern    Posn    *crepsearch P((Buffer *, int, int));
  889. extern    Posn    *showmatch P((void));
  890. extern    Posn    *find_pattern P((char *, int, int));
  891. extern    Posn    *fwd_word P((Posn *, int, bool_t));
  892. extern    Posn    *bck_word P((Posn *, int, bool_t));
  893. extern    Posn    *end_word P((Posn *, int, bool_t));
  894. extern    bool_t    dosearch P((Xviwin *, char *, int));
  895.  
  896. /*
  897.  * flexbuf.c
  898.  */
  899. extern    bool_t    flexaddch P((Flexbuf *, int));
  900. extern    char    *flexgetstr P((Flexbuf *));
  901. extern    int    flexpopch P((Flexbuf *));
  902. extern    void    flexdelete P((Flexbuf *));
  903. extern    bool_t    vformat P((Flexbuf *, char *, va_list));
  904. extern    bool_t    lformat P((Flexbuf *, char *, ...));
  905.  
  906. /*
  907.  * map.c
  908.  */
  909. extern    void    stuff P((char *, ...));
  910. extern    int    map_getc P((void));
  911. extern    void    map_char P((int));
  912. extern    void    map_timeout P((void));
  913. extern    bool_t    map_waiting P((void));
  914. extern    int    mapped_char P((int));
  915. extern    void    xvi_map P((int, char **, bool_t, bool_t));
  916. extern    void    xvi_keymap P((char *, char *));
  917. extern    void    xvi_unmap P((int, char **, bool_t, bool_t));
  918. extern    void    do_unmap P((int, char **, bool_t, bool_t));
  919.  
  920. /*
  921.  * mark.c
  922.  */
  923. extern    void    init_marks P((Buffer *));
  924. extern    bool_t    setmark P((int, Buffer *, Posn *));
  925. extern    void    setpcmark P((Xviwin *));
  926. extern    Posn    *getmark P((int, Buffer *));
  927. extern    void    clrmark P((Line *, Buffer *));
  928.  
  929. /*
  930.  * misccmds.c
  931.  */
  932. extern    bool_t    openfwd P((bool_t));
  933. extern    bool_t    openbwd P((void));
  934. extern    long    cntllines P((Line *, Line *));
  935. extern    long    cntplines P((Xviwin *, Line *, Line *));
  936. extern    long    plines P((Xviwin *, Line *));
  937. extern    Line    *gotoline P((Buffer *, unsigned long));
  938. extern    int    get_indent P((Line *));
  939. extern    int    set_indent P((Line *, int));
  940. extern    void    tabinout P((int, Line *, Line *));
  941. extern    void    makeargv P((char *, int *, char ***, char *));
  942.  
  943. /*
  944.  * mouse.c
  945.  */
  946. extern    void    mouseclick P((int, int));
  947. extern    void    mousedrag P((int, int, int, int));
  948.  
  949. /*
  950.  * movement.c
  951.  */
  952. extern    int    shiftdown P((Xviwin *, unsigned));
  953. extern    int    shiftup P((Xviwin *, unsigned));
  954. extern    void    scrolldown P((Xviwin *, unsigned));
  955. extern    void    scrollup P((Xviwin *, unsigned));
  956. extern    bool_t    oneup P((Xviwin *, long));
  957. extern    bool_t    onedown P((Xviwin *, long));
  958. extern    bool_t    one_left P((Xviwin *, bool_t));
  959. extern    bool_t    one_right P((Xviwin *, bool_t));
  960. extern    void    begin_line P((Xviwin *, bool_t));
  961. extern    void    coladvance P((Xviwin *, int));
  962. extern    void    do_goto P((long));
  963. extern    void    move_cursor P((Xviwin *, Line *, int));
  964. extern    void    move_window_to_cursor P((Xviwin *));
  965. extern    void    move_cursor_to_window P((Xviwin *));
  966.  
  967. /*
  968.  * normal.c
  969.  */
  970. extern    bool_t    normal P((int));
  971.  
  972. /*
  973.  * param.c
  974.  */
  975. extern    void    init_params P((void));
  976. extern    void    do_set P((Xviwin *, int, char **, bool_t));
  977. extern    void    set_param P((int, ...));
  978.  
  979. /*
  980.  * pipe.c
  981.  */
  982. extern    void    specify_pipe_range P((Xviwin *, Line *, Line *));
  983. extern    void    do_pipe P((Xviwin *, char *));
  984.  
  985. /*
  986.  * preserve.c
  987.  */
  988. extern    bool_t    preservebuf P((Xviwin *));
  989. extern    bool_t    do_preserve P((void));
  990.  
  991. /*
  992.  * ptrfunc.c
  993.  */
  994. extern    enum mvtype    inc P((Posn *));
  995. extern    enum mvtype    dec P((Posn *));
  996. extern    void    pswap P((Posn *, Posn *));
  997. extern    bool_t    lt P((Posn *, Posn *));
  998.  
  999. /*
  1000.  * screen.c
  1001.  */
  1002. extern    void    init_screen P((Xviwin *));
  1003. extern    void    updateline P((Xviwin *));
  1004. extern    void    update_sline P((Xviwin *));
  1005. extern    void    update_window P((Xviwin *));
  1006. extern    void    update_all P((void));
  1007. extern    void    redraw_screen P((void));
  1008. extern    void    clear P((Xviwin *));
  1009. extern    void    s_ins P((Xviwin *, int, int));
  1010. extern    void    s_del P((Xviwin *, int, int));
  1011. extern    void    s_inschar P((Xviwin *, int));
  1012. extern    void    wind_goto P((Xviwin *));
  1013. extern    void    cmd_init P((Xviwin *, int));
  1014. extern    Cmd_State
  1015.         cmd_input P((Xviwin *, int));
  1016. extern    char    *get_cmd P((Xviwin *));
  1017. extern    void    gotocmd P((Xviwin *, bool_t));
  1018. extern    void    prompt P((char *));
  1019. extern    void    beep P((Xviwin *));
  1020. extern    void    disp_init P((Xviwin *, char *(*) P((void)), int, bool_t));
  1021. extern    bool_t    disp_screen P((Xviwin *));
  1022.  
  1023. /*
  1024.  * search.c
  1025.  */
  1026. extern    Posn    *search P((Xviwin *, Line *, int, int, char **));
  1027. extern    Posn    *nsearch P((Xviwin *, Line *, int, int, char *));
  1028. extern    Line    *linesearch P((Xviwin *, int, char **));
  1029. extern    void    do_global P((Xviwin *, Line *, Line *, char *, bool_t));
  1030. extern    long    do_substitute P((Xviwin *, Line *, Line *, char *));
  1031. extern    long    do_ampersand P((Xviwin *, Line *, Line *, char *));
  1032. extern    long    do_tilde P((Xviwin *, Line *, Line *, char *));
  1033.  
  1034. /*
  1035.  * signal.c
  1036.  */
  1037. extern    void    ignore_signals P((void));
  1038. extern    void    catch_signals P((void));
  1039.  
  1040. /*
  1041.  * status.c
  1042.  */
  1043. extern    void    init_sline P((Xviwin *));
  1044. extern    void    show_message P((Xviwin *, char *, ...));
  1045. extern    void    show_error P((Xviwin *, char *, ...));
  1046. extern    void    show_file_info P((Xviwin *));
  1047.  
  1048. /*
  1049.  * tags.c
  1050.  */
  1051. extern    bool_t    set_tags P((Xviwin *, Paramval, bool_t));
  1052. extern    void    tagword P((void));
  1053. extern    bool_t    do_tag P((Xviwin *, char *, bool_t, bool_t, bool_t));
  1054.  
  1055. /*
  1056.  * undo.c
  1057.  */
  1058. extern    void    init_undo P((Buffer *));
  1059. extern    bool_t    start_command P((Xviwin *));
  1060. extern    void    end_command P((Xviwin *));
  1061. extern    void    replchars P((Xviwin *, Line *, int, int, char *));
  1062. extern    void    repllines P((Xviwin *, Line *, long, Line *));
  1063. extern    void    replbuffer P((Xviwin *, Line *));
  1064. extern    void    undo P((Xviwin *));
  1065. extern    bool_t    set_edit P((Xviwin *, Paramval, bool_t));
  1066.  
  1067. /*
  1068.  * windows.c
  1069.  */
  1070. extern    Xviwin    *init_window P((VirtScr *));
  1071. extern    void    free_window P((Xviwin *));
  1072. extern    Xviwin    *split_window P((Xviwin *));
  1073. extern    void    map_window_onto_buffer P((Xviwin *, Buffer *));
  1074. extern    void    unmap_window P((Xviwin *));
  1075. extern    Xviwin    *next_window P((Xviwin *));
  1076. extern    Xviwin    *find_window P((Xviwin *, char *));
  1077. extern    void    resize_window P((Xviwin *, int));
  1078. extern    int    move_sline P((Xviwin *, int));
  1079. extern    void    update_buffer P((Buffer *));
  1080. extern    bool_t    can_split P((void));
  1081.  
  1082. /*
  1083.  * yankput.c
  1084.  */
  1085. extern    void    init_yankput P((void));
  1086. extern    bool_t    do_yank P((Buffer *, Posn *, Posn *, bool_t, int));
  1087. extern    bool_t    yank_str P((int, char *, bool_t));
  1088. extern    void    do_put P((Xviwin *, Posn *, int, int));
  1089. extern    void    yp_stuff_input P((Xviwin *, int, bool_t));
  1090. extern    void    yp_push_deleted P((void));
  1091.